package com.wck.car.controller;

import com.wck.car.CarBrandDescService;
import com.wck.car.CarBrandInfoService;
import com.wck.car.model.CarBrandDesc;
import com.wck.car.model.CarBrandInfo;
import com.wck.car.oyz.CarBrandDescType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
public class CarBrandDescController {

    @Resource
    private CarBrandDescService carBrandDescService;

    @Resource
    private CarBrandInfoService carBrandInfoService;



    @PostMapping("/getCarInfoList")
    public void getCarInfoList(){
        List<CarBrandInfo> list = carBrandInfoService.lambdaQuery().select(CarBrandInfo::getBrandLink,CarBrandInfo::getId).list();
        ArrayList<CarBrandDesc> brandDescList = new ArrayList<>();
        //通过循环list集合拿到品牌对象
        list.parallelStream().forEach(e->{
            List<CarBrandDesc> carHtml = CarBrandDescType.getCarHtml(e);
            carBrandInfoService.updateById(e);      //修改品牌简介
            brandDescList.addAll(carHtml);
        });
        boolean b = carBrandDescService.saveBatch(brandDescList);
    }

}
